<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once('Entity/Skill_Video_Categories_Entity.php');        
class Skill_Video_Categories_Model extends Skill_Video_Categories_Entity
{  
    public function __construct()
    {
        parent::__construct();
    }
    
    private function delete_byVid($vid)
    {
        $this->db->where('id > ', 0);
        $this->db->where('vid', $vid);
        return $this->db->delete('skill_video_categories');    
    }
    
    public function update($vid, $arrCid)
    {
        $this->delete_byVid($vid);
        $this->saveVC($vid, $arrCid);
    }
    
    public function saveVC($vid, $arrCid)
    {
        foreach ($arrCid as $cid) {
            $this->setVid($vid);
            $this->setCid($cid);
            $this->save();
        }
    }
    
    public function getbyVid($vid)
    {
        $sql = "SELECT c.cid
            FROM skill_video_categories c
            WHERE vid = ? ";
        $query = $this->db->query($sql, array($vid));
        if ($query->num_rows() > 0) {
            return $query->result_object();
        }
        return array();   
    }
    
    public function arrCid($vid)
    {
        $result = $this->getbyVid($vid);
        $arr = array();
        foreach ($result as $row) {
            $arr[] = $row->cid;
        }
        return $arr;
        
    }
}